<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>航班信息</title>
    <link rel="stylesheet" href="../../../css/iconfont/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <link rel="stylesheet" href="../../../css/index/train/train_message.css"/>
    <link rel="stylesheet" href="../../../css/index/aircraft/plane_info.css">

</head>
<body style="cursor: pointer;">

<div class="detail_plane" style="overflow:auto;">
  <div class="date_week">
    <div>
      <p class="week_style" style="font-size:0.6rem;text-align:right;">
        <span class="s_date">09-06</span>
        <span class="s_week">周四</span>
      </p>
      <p class="plane_time s_time"></p>
    </div>
    <div style="margin-top:0.5rem;">
      <p class="week_style" style="font-size:0.6rem;text-align:right;">
        <span class="e_date">09-06</span>
        <span class="e_week">周四</span>
      </p>
      <p class="plane_time e_time"></p>
    </div>
  </div>
  <div class="plane_place">
    <div class="plane_icon">
      <i class="iconfont icon-gangjing" style="font-size:3.5rem;color:#DEE4E7;"></i>
    </div>
    <div style="padding:0.5rem 0;">
      <div class="s_place"></div>
      <div class="e_place" style="margin-top:1.8rem;"></div>
    </div>
  </div>
  <div class="number_type">
    <p class="week_style flight_number"></p>
    <p class="type_name week_style"></p>
    <p class="duration week_style" style="font-size:0.6rem;"></p>
  </div>
    <!-- <div class="detail_time"> -->
        <!-- <div class="start_time"> -->
            <!-- <p class="s_time"></p><!--例：22:30-->
            <!-- <p class="s_place"></p><!--例：太原T2-->
        <!-- </div> -->
        <!-- <div class="expenditure_time"> -->
            <!-- <span class="duration"></span><!--例：24小时30分-->
            <!-- <i class="iconfont icon-lianjie"></i> -->
        <!-- </div> -->
        <!-- <div class="end_time"> -->
            <!-- <p class="e_time"></p><!--例：05:13-->
            <!-- <p class="e_place"></p><!--例：北京T3-->
        <!-- </div> -->
    <!-- </div> -->
    <!-- <div style="text-align: center;color:#ffffff;padding-bottom: 1rem;" class="type_name"></div> -->
</div>
<div class="all_seat">
    <ul id="seat_list">
    </ul>
</div>
<div class="order_type" style="display: none;">
    <ul>
        <li onclick="public_self()" style="height: auto!important;">
            <div class="reason"  style="text-align: left;width:86%;white-space:nowrap; text-overflow:ellipsis; overflow:hidden;">
                <p>因公，为本人预定</p>
                <p class="policy">差旅政策：</p>
            </div>
            <div class="detail_right">
                <i class="aui-iconfont aui-icon-right"></i>
            </div>
        </li>
        <li onclick="train_people()">
            <div class="reason">
                <p>因公，为他人/多人预定</p>
                <p style="text-align: left">请选择乘客</p>
            </div>
            <div class="detail_right">
                <i class="aui-iconfont aui-icon-right"></i>
            </div>
        </li>
        <!-- <li onclick="private_others()">
            <div class="reason">
                <p style="text-align: left">因私预定</p>
                <p>不受差旅政策限制,直接预订</p>
            </div>
            <div class="detail_right">
                <i class="aui-iconfont aui-icon-right"></i>
            </div>
        </li> -->
    </ul>
</div>
  <div id="shade" class='aui-hide' onclick="closefun(this)"></div>
</body>
<script src="../../../script/aui/api.js" ></script>
<script src="../../../script/aui/aui-dialog.js" ></script>
<script src="../../../script/aui/aui-toast.js" ></script>
<script src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script src="../../../script/config.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>
<script src="../../../script/widget/js-time.js"></script>
<script id="aircrafttmp" type="text/x-dot-template">
    {{ for(var prop in it) { }}
    <div class="aui-list-item aui-list-item-inner" onclick="call_photo(this)">
        <div class="aui-list-item-title">
            <div class="aui-hide plane_number">{{=it[prop]['flight_number']}}</div>
            <span class="start_time">{{=it[prop]['take_off_time']}}</span>
            <span class="end_time">{{=it[prop]['to_ground_time']}}</span>
            <span class="start_adder">{{=it[prop]['take_off_place']}}{{=it[prop]['take_off_floor']}}</span>
            <span class="information-to">{{=it[prop]['airline_name']}}{{=it[prop]['flight_number']}}</span>
            <span class="end_adder">{{=it[prop]['to_ground_place']}}</span>
            <!--<span class="information-from">{{=aircraf_end_site}}</span>-->
            {{? it[prop]['flight_minute'] }}
            <span class="duration">{{=it[prop]['flight_hours']}}小时{{=it[prop]['flight_minute']}}分</span>
            {{??}}
            <span class="duration">{{=it[prop]['flight_hours']}}小时00分</span>
            {{?}}
            <i class="iconfont icon-lianjie"></i>
        </div>
        <div class="aui-list-item-right">
            <p><e>￥</e>{{=it[prop]['price']}}</p>
            <p>{{=it[prop]['discount']}}折{{=it[prop]['shipping_space']}}</p>
        </div>
    </div>
    {{ } }}
</script>
<script>
var planeInfo,selected_staff,isApply,order_self,order_type;
apiready = function(){
  api.parseTapmode();
  planeInfo = api.pageParam.planeInfo;//接收参数
  selected_staff = api.pageParam.selected_staff;

  isApply = $api.getStorage('isApply');//是否开启申请单的状态 1开启   0关闭
  order_self = $api.getStorage('order_self');//因公为本人:2   因公为他人：3   因私：1
  order_type = $api.getStorage('order_type');


  $('#seat_list').empty();
  var param = {};
  var flight_number   = planeInfo.flight_number;//航班号
  var date            = planeInfo.date;//起飞日期
  var date1 = date.split('/');
  var off_code        = planeInfo.off_code;//出发机场code
  var ground_code     = planeInfo.ground_code;//目地机场名称code
  var time            = planeInfo.time;//起飞时间
  var carrier         = planeInfo.carrier;//航空公司两字码
  $('.flight_number').text(planeInfo.information_to);//东航MU5294
  $('.s_date').text(date1[1]+'-'+date1[2]);//起飞日期
  $('.s_week').text(planeInfo.week);//起飞日期周几
  $('.s_time').text(time);//起飞时间
  $('.e_time').text(planeInfo.end_time);//到达时间

  $('.duration').text(planeInfo.duration);//时长
  $('.type_name').text(planeInfo.airline_model);//机型

  $('.start_date').text(date1[1]+'月'+date1[2]+'日');
  param.url = Config.plane.flightInfo;
  param.data = {from:off_code,arrive:ground_code,date:date,time:time,carrier:carrier,flight_no:flight_number};
  getPlaneList(param);
}
    //获取航班信息
    var toast = new auiToast();
    function getPlaneList(param){

        var html = '';
        var str = '';
        var right_btn = '';
        $('body').css('background','#ffffff');
        ajax(param,function(data){
          $('body').css('background','#78DDFF');
          $('body').css('padding','0.5rem');
            if (data.code == 1) {
                $('.s_place').text(data.data.take_off_place_name);//起飞站(深圳宝安T3)
                $('.e_place').text(data.data.to_ground_place_name);//到达站
                $api.setStorage('carrier_fullname',data.data.carrier_fullname);//航空公司名称
                $api.setStorage('cover_charge',data.data.cover_charge);//机建
                $api.setStorage('fuel_charge',data.data.fuel_charge);//燃油
                var e_date = data.data.arrive_date.split('-');
                $('.e_date').text(e_date[1]+'-'+e_date[2]);//到达日期
                $('.e_week').text(getDay(new Date(e_date)));//到达日期周几
                var res = data.data.list;
                $.each(res,function(key,val){
                    if (val.office != '') {
                        str = '<div class="plane_center"><span class="office">'+val.office +'</span></div>';
                    }else{
                        str = '<div class="plane_center"><span class="office" style="background: white;"></span></div>';
                    }
                    if (val.seat == '机票充足') {
                        right_btn = '<div style="height:2.5rem;width:2.5rem;background:#FF990F;border-radius:0.3rem;border:1px solid #FFA52B;" onclick="price_click(this)">'+
                                        '<div style="width:2.4rem;line-height:2.4rem;border-radius:0.3rem;background:#FF990F;text-align:center;color:#ffffff;">预订</div>'
                                    '</div>';
                    } else {
                        right_btn = '<div style="height:2.5rem;width:2.5rem;border-radius:0.3rem;border:1px solid #FFA52B;" onclick="price_click(this)">'+
                                      '<div style="line-height:1.5rem;width:2.4rem;background:#FF990F;border-radius:0.25rem 0.25rem 0 0;text-align:center;color:#ffffff;">预订</div>'+
                                      '<div style="height:0.9rem;line-height:0.9rem;width:2.4rem;text-align:center;border-radius:0 0 0.25rem 0.25rem;background:#ffffff;color:#FCA950;font-size:0.7rem;">'+val.seat+'</div>'+
                                    '</div>';
                    }
                    html += '<div style="padding: 0 0.8rem;background:#ffffff;margin:0.5rem 0;"><li>' +
                        '            <div class="shipping_price">' +
                        '                <div class="plane_left" onclick="remarkClick(this)">' +
                        '                    <p><span class="space_type">'+val.shipping_space_name+'('+ val.shipping_space +')</span></p>' +
                        '                    <p><span style="font-size:0.5rem;color:#FF980D;">￥</span><span class="now_price" style="color:#FF980D;font-size:1.2rem;">'+val.price+'</span></p>'+
                        '                    <p><span class="space_exit">退改签</span><span class="discount">'+val.discount+'</span>折 <span class="aui-hide shipping_code">'+val.shipping_space+'</span></p>' +
                        '                </div>' +
                        str+
                        '                <div class="plane_right">' +
                        right_btn+
                        '                </div>'+
                        '            </div>' +
                        '        </li>';
                    html += '<div class="aui-hide remarkExit" >' +
                        '<div style="width:100%;text-align:center;">'+
                        '<span style="display:block;width:4rem;font-size:0.7rem;margin:auto;padding:0.1rem;border:1px solid #B2CBF9;border-radius:0.3rem;">退改规定</span>'+
                        '</div>'+
                        '    <table style="margin: 0.5rem; border-collapse: collapse;">' +
                        '        <tr class="tabtr" style="background:#F6FAFE;">' +
                        '            <td class="lefttd">舱位</td>' +
                        '            <td class="righttd" style="height:2rem;vertical-align: middle;">'+val.shipping_space_name+'</td>' +
                        '        </tr>' +
                        '        <tr class="tabtr">' +
                        '            <td class="lefttd">退票规定</td>' +
                        '            <td class="righttd">' +val.retreating_content.retreat+
                        '            </td>' +
                        '        </tr>' +
                        '        <tr class="tabtr" style="background:#F6FAFE;">' +
                        '            <td class="lefttd">同舱改期费</td>' +
                        '            <td class="righttd">' +val.retreating_content.change+
                        '            </td>' +
                        '        </tr>' +
                        '        <tr class="tabtr">' +
                        '            <td class="lefttd">签转</td>' +
                        '            <td class="righttd" style="vertical-align: middle;">'+val.retreating_content.sign+'</td>' +
                        '        </tr>' +
                        '        <tr class="tabtr" style="background:#F6FAFE;">' +
                        '            <td class="lefttd">特殊说明</td>' +
                        '            <td class="righttd">' +
                        '               <p>*该退改签规则仅供参考，以航空公司最新规定为准*</p>' +
                        '               <p>*凡是客票中备注了不得退票的，退票只退税费*</p>' +
                        '            </td>' +
                        '        </tr>' +
                        '    </table>' +
                        '</div></div>';
                });
                $('#seat_list').append(html);
            } else {
              $toast('接口请求超时，请重新获取！',2000,'m');
            }
        })
    }
    var dialog = new auiDialog({});
    //点击价格按钮
    var policy = $(".order_type").html();
    var is_violation = '';
    var violation_reservation = '';
    var check_msg = '';
    plane_msg = {};
    var is_alert;
    function price_click(obj){
        var office = $(obj).parent().parent().find('.office').text();
        //选择舱位和航班信息存入session
        plane_msg = {
            'space_type'     : $(obj).parent().parent().find('.space_type').text(),//舱位类型
            'discount'       : $(obj).parent().parent().find('.discount').text(),//折扣
            'now_price'      : $(obj).parent().parent().find('.plane_left .now_price').text(),//对应舱位价格
            'shipping_code'  : $(obj).parent().parent().find('.shipping_code').text(),//舱位代码
            'office'         : office//是否官网直销价
        };
        //机票第一次验价   office为空需验价，走龙之舟接口    不为空，暂时走拦截订单
        if (office == '') {
            //机票验价
            var params  = {};
            params.url  = Config.plane.checkPlaneTicket;
            params.data = {boardPoint:planeInfo.off_code,offPoint:planeInfo.ground_code,carrier:planeInfo.carrier,flightNo:planeInfo.flight_number.slice(2),departureDate:planeInfo.date,departureTime:planeInfo.time,classCode:$(obj).parent().parent().find('.shipping_code').text()};
            //请求接口
            ajax(params,function(res){
                if(res.code == 1){
                    //判断是否开启申请单
                    if (isApply == 1) {
                        if (order_self == 3) {
                              //打开差旅政策页面(因公为他人跳转差旅政策页面)
                              open_policy();
                        } else if (order_self == 2) {
                              //打开提交页面（因公为本人和因私跳转提交页面）
                              var str = res.data.join(',');
                              if(str.indexOf($(obj).find('.now_price').text()) != -1){
                                  //计算今天到选择日期的天数
                                  var nowTime = Date.parse(new Date());
                                  var newTime = Date.parse(new Date(planeInfo.date));
                                  var timeAll = Math.floor((newTime-nowTime)/86400000)+1;
                                  //获取个人的差旅政策
                                  var paramss  = {};
                                  paramss.url  = Config.common.myPlanePolicy;
                                  paramss.data = {days:timeAll,discount:$(obj).parent().parent().find('.discount').text(),userIds:$api.getStorage('user_id')};
                                  ajax(paramss,function(data){
                                      if (data.code == 1) {
                                        $api.setStorage('policy_id', data.data[0].policy_id);
                                          var plane = data.data[0].policy_details;
                                          $('.policy').html(plane);
                                          is_violation = data.data[0].is_violation;
                                          violation_reservation = data.data[0].violation_reservation;
                                          check_msg = data.data[0].check_msg;
                                          public_self();
                                      }
                                  });
                              }else{
                                  alert('预定失败，请选择其他仓位机票!');
                              }

                        } else {
                          //因私选择出行人
                              open_people();
                        }
                    } else {
                      if (order_type == 1) {//因公
                        var str = res.data.join(',');
                        if(str.indexOf($(obj).find('.now_price').text()) != -1){
                          //计算今天到选择日期的天数
                          var nowTime = Date.parse(new Date().getFullYear()+'/'+(new Date().getMonth()+1)+'/'+new Date().getDate());
                          var newTime = Date.parse(new Date(planeInfo.date));
                          var timeAll = Math.floor((newTime-nowTime)/86400000)+1;

                          //获取个人的差旅政策
                          var param  = {};
                          param.url  = Config.common.myPlanePolicy;
                          param.data = {days:timeAll,discount:$(obj).parent().parent().find('.discount').text(),userIds:$api.getStorage('user_id')};
                          ajax(param,function(data){
                              if (data.code == 1) {
                                dialog.alert({
                                    title:"选择订单类型",
                                    msg:policy,
                                    buttons:['取消']
                                },function(ret){
                                    console.log(ret);
                                })
                                  var plane = data.data[0].policy_details;
                                  $('.policy').html(plane);
                                  is_violation = data.data[0].is_violation;
                                  violation_reservation = data.data[0].violation_reservation;
                                  check_msg = data.data[0].check_msg;
                                  $api.setStorage('policy_id', data.data[0].policy_id);
                              }
                          });


                        }else{
                            alert('预定失败，请选择其他仓位机票!');
                        }
                      } else {//因私
                            //选择出行人
                            open_people();
                      }

                    }
                } else {
                  $toast(res.msg);
                }
            })
        } else {
          if (isApply == 1) {
            if (order_self == 3) {
                  //打开差旅政策页面(因公为他人跳转差旅政策页面)
                  open_policy();
            } else if (order_self == 2) {
              //计算今天到选择日期的天数
              var nowTime = Date.parse(new Date());
              var newTime = Date.parse(new Date(planeInfo.date));
              var timeAll = Math.floor((newTime-nowTime)/86400000)+1;
              //获取个人的差旅政策
              var paramss  = {};
              paramss.url  = Config.common.myPlanePolicy;
              paramss.data = {days:timeAll,discount:$(obj).parent().parent().find('.discount').text(),userIds:$api.getStorage('user_id')};
              ajax(paramss,function(data){
                  if (data.code == 1) {
                      $api.setStorage('policy_id', data.data[0].policy_id);
                      var plane = data.data[0].policy_details;
                      $('.policy').html(plane);
                      is_violation = data.data[0].is_violation;
                      violation_reservation = data.data[0].violation_reservation;
                      check_msg = data.data[0].check_msg;
                      public_self();
                  }
              });
            } else {
              //因私选择出行人
                  open_people();
            }
          } else {
              if (order_type == 1) {//因公
                //计算今天到选择日期的天数
                var nowTime = Date.parse(new Date());
                var newTime = Date.parse(new Date(planeInfo.date));
                var timeAll = Math.floor((newTime-nowTime)/86400000)+1;
                //获取个人的差旅政策
                var param  = {};
                param.url  = Config.common.myPlanePolicy;
                param.data = {days:timeAll,discount:$(obj).parent().parent().find('.discount').text(),userIds:$api.getStorage('user_id')};
                ajax(param,function(data){
                    if (data.code == 1) {
                      dialog.alert({
                          title:"选择订单类型",
                          msg:policy,
                          buttons:['取消']
                      },function(ret){
                          console.log(ret);
                      })
                        var plane = data.data[0].policy_details;
                        $('.policy').html(plane);
                        is_violation = data.data[0].is_violation;
                        violation_reservation = data.data[0].violation_reservation;
                        check_msg = data.data[0].check_msg;
                        $api.setStorage('policy_id', data.data[0].policy_id);
                    }
                });

              } else {
                //选择出行人
                open_people();
              }

          }
        }
    }

    //退改规定弹框
    function remarkClick(obj){
      $(obj).parent().parent().parent().find('.remarkExit').removeClass('aui-hide').addClass('aui-show');
      $('#shade').removeClass('aui-hide').addClass('aui-show');
        // var remarkExit=$(obj).parent().parent().parent().find('.remarkExit').html();
        // dialog.alert({
        //     title:"退改规定",
        //     msg:remarkExit,
        //     buttons: ['确定']
        // },function(ret){
        //     console.log(ret)
        // })
    }
    //关闭弹框
    function closefun(obj){
        $(obj).removeClass('aui-show').addClass('aui-hide');
        $('.remarkExit').removeClass('aui-show').addClass('aui-hide');
    }
    $api.setStorage('card_submit_type',1);
    //因公为自己预定
    function public_self(){
        if (is_violation && violation_reservation == 0) {
            alert('当前政策标准违规,不允许违规预定');
            return false;
        }
        //   如果能预定直接跳转到提交订单页面,如果不能判断能不能违规预定
        if (is_violation) {
            $api.setStorage('check_msg',check_msg);
            $api.setStorage('trip_policy',0);//违规标识 0违规  1不违规
            $api.setStorage("is_violation",is_violation);
            // alert('当前政策标准违规,不允许违规预订');
            // return false;
        } else {
            $api.setStorage('trip_policy',1);
            $api.setStorage("is_violation",is_violation);
        }
        $api.setStorage('order_self',2);//因公因私标识 3因公为他人 2因公为本人 1因私
        $api.setStorage("book_type",'0');//预订类型  0因公为本人预订   1因公位他人预订 2因私预订
        open_submit();
    }
    //因公为他人预定
    function train_people(){
        $api.setStorage("order_self",3);
        open_people();

    }

    //因私为他人预定
    function private_others(){
      $api.setStorage("order_self",1);
        open_people();
    }

    //差旅政策页面
    function open_policy(){
      api.openWin({
          name: 'travel_policy_win',
          url: '../common/travel_policy_win.html',
          pageParam: {
              selected_staff: selected_staff,
              plane_msg     : plane_msg,
              planeInfo     : planeInfo
          }
      });
    }
    //选择出行人
    function open_people(){
        api.openWin({
            name: 'travel_people_frm',
            url: '../common/travel_people_frm.html',
            pageParam: {
              plane_msg : plane_msg,
              planeInfo : planeInfo
            }
        });

    }
    //打开提交页面
    function open_submit(){
      api.openWin({
          name: 'plane_order_win',
          url: './plane_order_win.html',
          pageParam: {
              plane_msg : plane_msg,
              planeInfo : planeInfo
          }
      });
    }

</script>
</html>
